import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';
import format from '@dfeidao/atom-web/dt/format';
interface Par extends Event{
	page_no:number
}
export default async function a003(fd: IFeidaoAiBrowserComponent,e:Par) {
// todo
const res =await nodejs<{dt:Array<{work_bill_no:string,job_content:string,cust_name:string,project_name:string,project_no:string,create_time:number,source_type:string,work_order_status:string}>;c:number}>("test-web/zj-000003/s001",{filter:{Pn:e.page_no}});
const ret=Array();

for (let i = 0; i < res.dt.length; i++) {
	if(res.dt[i].source_type=="1"){
		res.dt[i].source_type="总服务台";
	}else if(res.dt[i].source_type=="2"){
		res.dt[i].source_type="服务台";
		
	}else if(res.dt[i].source_type=="3"){
		res.dt[i].source_type="客户报障";

	}else{
		res.dt[i].source_type="内部报障";
	}
	
}
for (let i = 0; i < res.dt.length; i++) {

if(res.dt[i].work_order_status=="1"){
	res.dt[i].work_order_status="结单";
}else if(res.dt[i].work_order_status=="2"){
	res.dt[i].work_order_status="完成";

}else if(res.dt[i].work_order_status=="3"){
	res.dt[i].work_order_status="挂起";

}else if(res.dt[i].work_order_status=="4"){
	res.dt[i].work_order_status="未派单";
}else{
	res.dt[i].work_order_status="进行中";
}
}
for (let i = 0; i < res.dt.length; i++) {
		ret[i]=res.dt[i].project_no;
	
}

const  res1=await nodejs<{d1:Array<{equip_depart_no:string,project_no:string,equip_depart_name:string}>}>("test-web/zj-000003/s002",{
	filter:{ 
		project_no:ret
	}
});
const p=res.dt.map((n)=>{
	return {...n,create_time:format(n.create_time,2)}
})
const arr = Array()
for (let index = 0; index < res.dt.length; index++) {
	for (let i = 0; i < res1.d1.length; i++) {
		// if(res.dt[index].project_no==res1.d1[i].project_no){
			arr[index] = {work_bill_no:res.dt[index].work_bill_no,job_content:res.dt[index].job_content,source_type:res.dt[index].source_type,
				cust_name:res.dt[index].cust_name,project_name:res.dt[index].project_name,work_order_status:res.dt[index].work_order_status,create_time:p[index].create_time,equip_depart_name:res1.d1[i].equip_depart_name}

		// }
	}
}

const dtNO = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
const dtH = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
if (arr.length > 0) {
	render(fd, arr, p001, 'p001', 'inner');
	dtNO.style.display = 'block';
	dtH.style.display = 'none';
} else {
	render(fd, '', p002, 'p002', 'inner');
	dtNO.style.display = 'none';
	dtH.style.display = 'block';
}
if (arr.length > 20) {
	render(fd, arr.length, p003, 'p003', 'inner');
}

}
